package collection.list;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

//模拟KTV点歌系统
public class Demo02KTV {

    private static List<String> list = new ArrayList<>();

    public static void main(String[] args) {
        initsong();
    }

    //初始化歌曲列表函数
    private static void initsong() {
        list.add("牧马城市");
        list.add("我叫长安，你叫故里");
        list.add("窗");
        list.add("清空");
        list.add("时光背面的我");
        list.add("落日与晚风");
        list.add("白月光与朱砂痣");
        list.add("不如");
        mainScreen();
    }

    //页面函数
    private static void mainScreen() {
        System.out.println("========欢迎来到心悦KTV========");
        System.out.println("1.查看列表");
        System.out.println("2.置顶歌曲");
        System.out.println("3.移到上一首");
        System.out.println("4.移除歌曲");
        System.out.println("5.添加歌曲");
        System.out.println("0.退出系统");

        Scanner scanner = new Scanner(System.in);
        System.out.println("输入你的操作:");
        int i = scanner.nextInt();
        switch (i) {
            case 0:
                System.exit(0);
                break;
            case 1:
                showSong();
                break;
            case 2:
                toTop();
                break;
            case 3:
                break;
            case 4:
                delete();
                break;
            case 5:
                add();
                break;
        }
    }

    private static void show() {
        System.out.println("歌曲有：");
        int num = 0;
        for (String s : list) {
            System.out.println(num + ", " + s);
            num++;
        }
    }

    private static void showSong() {
        show();
        mainScreen();
    }

    private static void toTop() {
        System.out.println("请输入要置顶歌曲的序号");
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        String temp = list.get(i);
        list.add(0, list.remove(i));
        show();
        mainScreen();
    }

    private static void delete() {
        System.out.println("请输入想删除歌曲的序号:");
        Scanner scanner = new Scanner(System.in);
        int i = scanner.nextInt();
        list.remove(i);
        System.out.println("该歌曲已移除，新的歌单为: ");
        show();
        mainScreen();
    }

    private static void add() {
        System.out.println("请输入想添加的歌曲名:");
        Scanner scanner = new Scanner(System.in);
        String song = scanner.nextLine();
        list.add(song);
        System.out.println("该歌曲已添加，新的歌单为: ");
        show();
        mainScreen();
    }
}
